/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.webos.java.rssreader;

import org.json.JSONObject;
import org.webos.java.base.Dialog;
import org.webos.java.base.DialogType;
import org.webos.java.base.RemoteMessage;

/**
 *
 * @author kostya
 */
@DialogType(jsClass="rssreader.Settings")
public class SettingsDialog extends Dialog<RSSReader>{

    public SettingsDialog(RSSReader aRSSReader) {
        super(aRSSReader);

        getData().putOpt("show_notify", aRSSReader.foldersFeeds.showNotify);
        getData().putOpt("items_age", aRSSReader.foldersFeeds.itemsTotal);
        getData().putOpt("update_min", aRSSReader.foldersFeeds.updateTimeout);
        getData().putOpt("load_total", aRSSReader.entries.loadItems);
        getData().putOpt("show_by", getApplication().options.optInt("show_by", 20));

        show();
    }

    @RemoteMessage
    public void okClick(JSONObject aData){
        getApplication().foldersFeeds.showNotify = aData.optBoolean("show_notify", false);
        getApplication().options.putOpt("show_notify",
                getApplication().foldersFeeds.showNotify);
        getApplication().foldersFeeds.itemsTotal = aData.optInt("items_age", 200);
        getApplication().options.putOpt("items_age",
                getApplication().foldersFeeds.itemsTotal);
        getApplication().foldersFeeds.updateTimeout = aData.optInt("update_min", 15);
        getApplication().options.putOpt("update_min",
                getApplication().foldersFeeds.updateTimeout);
        getApplication().entries.loadItems = aData.optInt("load_total", 15);
        getApplication().options.putOpt("load_total",
                getApplication().entries.loadItems);
        getApplication().options.putOpt("show_by", aData.optInt("show_by", 20));
        getApplication().setOption("options", getApplication().options.toString());
        closeDialog(aData);
    }
}
